
function [successClass] = bayes_4(classA1, classA2, classA3, classA4, classTest)

y1(1:length(classA1)) = 1;
y2(1:length(classA2)) = 2;
y3(1:length(classA3)) = 3;
y4(1:length(classA4)) = 4;


yTest1(1:length(classTest)) = 1;
yTest2(1:length(classTest)) = 2;
yTest3(1:length(classTest)) = 3;
yTest4(1:length(classTest)) = 4;

s1 = size(classA1);
s2 = size(classA2);
s3 = size(classA3);
s4 = size(classA4);
sTest = size(classTest);

data1 = struct('X', classA1', 'y', y1, 'dim', s1(2), 'num_dat', length(y1));
data2 = struct('X', classA2', 'y', y2, 'dim', s2(2), 'num_dat', length(y2));
data3 = struct('X', classA3', 'y', y3, 'dim', s3(2), 'num_dat', length(y3));
data4 = struct('X', classA4', 'y', y4, 'dim', s4(2), 'num_dat', length(y4));


model.Pclass{1} = mlcgmm(data1);
model.Pclass{2} = mlcgmm(data2);
model.Pclass{3} = mlcgmm(data3);
model.Pclass{4} = mlcgmm(data4);
model.Prior     = [length(classA1) length(classA2) length(classA3) length(classA4)] / ...
    (length(classA1)+length(classA2)+length(classA3)+length(classA4));


ypred= bayescls(classTest', model);
successClass = [1-cerror(ypred, yTest1), 1-cerror(ypred, yTest2), 1-cerror(ypred, yTest3), 1-cerror(ypred, yTest4)];


hold on
if(sTest(2)==3)
    plot3(classA1(:,1), classA1(:,2), classA1(:,3), 'ro');
    plot3(classA2(:,1), classA2(:,2), classA2(:,3), 'go');
    plot3(classA3(:,1), classA3(:,2), classA3(:,3), 'bo');
    plot3(classA4(:,1), classA4(:,2), classA4(:,3), 'mo');
    plot3(classTest(:,1), classTest(:,2), classTest(:,3), 'yo');
elseif(sTest(2)==2)
    plot(classA1(:,1), classA1(:,2), 'ro');
    plot(classA2(:,1), classA2(:,2), 'go');
    plot(classA3(:,1), classA3(:,2), 'bo');
    plot(classA4(:,1), classA4(:,2), 'mo');
    plot(classTest(:,1), classTest(:,2), 'yo');
end

end
